package com.example.mobile2121606062ylj0331;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity {
    private RadioGroup g1;
    private RadioButton t11;
    private RadioButton t12;
    private RadioButton t13;
    private RadioGroup g2;
    private RadioButton t21;
    private RadioButton t22;
    private RadioButton t23;
    private RadioButton t24;
    private Button b1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();






        g1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton=findViewById(i);
                Log.i("g1",radioButton.getText().toString());
            }
        });
        g2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton=findViewById(i);
                Log.i("g2",radioButton.getText().toString());
            }
        });
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String msg="";
                int carTypeId=g1.getCheckedRadioButtonId();
                if(carTypeId!=-1){
                    msg=((RadioButton)findViewById(carTypeId)).getText().toString();
                }else {
                    msg="未选车型";
                }
                int roomId=g2.getCheckedRadioButtonId();
                if(roomId!=-1){
                    msg+=","+((RadioButton)findViewById(roomId)).getText().toString();
                }else {
                    msg+=",未选生产车间";
                }
                Log.i("Button",msg);
            }
        });






    }
    private void initView() {
        g1 = (RadioGroup) findViewById(R.id.g1);
        t11 = (RadioButton) findViewById(R.id.t11);
        t12 = (RadioButton) findViewById(R.id.t12);
        t13 = (RadioButton) findViewById(R.id.t13);
        g2 = (RadioGroup) findViewById(R.id.g2);
        t21 = (RadioButton) findViewById(R.id.t21);
        t22 = (RadioButton) findViewById(R.id.t22);
        t23 = (RadioButton) findViewById(R.id.t23);
        t24 = (RadioButton) findViewById(R.id.t24);
        b1 = (Button) findViewById(R.id.b1);
    }
}